package com.hmall.controller;

import com.hdmall.business.common.common.ServerResponse;
import com.hmall.model.MallBanner;
import com.hmall.vo.MallHotVo;
import com.hmall.model.SysUser;
import com.hmall.service.MobileHomeService;
import com.hmall.util.TokenUtil;
import com.hmall.vo.MallShopVo;
import com.hmall.vo.ProductShowVo;
import com.hmall.vo.UserLikeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import redis.clients.jedis.JedisPool;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author zhoutao
 */
@RestController
@RequestMapping("/home/")
@Api(value = "手机首页API", description = "手机首页展示接口")
public class MobileHomeController {

    private final JedisPool jedisPool;

    private final MobileHomeService iMobileHomeService;


    TokenUtil tokenUtil = new TokenUtil();

    @Autowired
    public MobileHomeController(JedisPool jedisPool, MobileHomeService iMobileHomeService) {
        this.jedisPool = jedisPool;
        this.iMobileHomeService = iMobileHomeService;
    }

    /**
     * @return com.hmall.common.ServerResponse<java.util.List   <   com.hmall.vo.MallHotVo>>
     * @Date 2018/11/9 14:17
     * @Param [hotCount, shopId]
     * @Description // 通用热销
     */
    @GetMapping("hotList")
    @ApiOperation(value = "热销")
    public ServerResponse<List<MallHotVo>> listHotProduct(@RequestParam(value = "hotCount", defaultValue = "10") int hotCount,
                                                          @RequestParam(value = "shopId", defaultValue = "1") int shopId) {

        return iMobileHomeService.listHotProduct(hotCount, shopId);

    }

    /**
     * @return com.hmall.common.ServerResponse<java.util.List   <   com.hmall.vo.ProductShowVo>>
     * @Date 2018/11/9 14:17
     * @Param []
     * @Description // 首页产品展示
     */
    @GetMapping("showProduct")
    @ApiOperation(value = "产品展示")
    public ServerResponse<List<ProductShowVo>> showProduct() {

        return iMobileHomeService.showProduct();
    }

    /**
     * @return com.hmall.common.ServerResponse<java.util.List   <   com.hmall.vo.MallShopVo>>
     * @Date 2018/11/9 14:17
     * @Param [count]
     * @Description //
     * 首页商铺推荐商铺展示
     * 默认六条
     */
    @GetMapping("showShop")
    @ApiOperation(value = "商铺展示")
    public ServerResponse<List<MallShopVo>> showShop(@RequestParam(value = "count", defaultValue = "6") Integer count) {

        return iMobileHomeService.showShop(count);
    }


    /**
     * @return com.hmall.common.ServerResponse<java.util.List   <   com.hmall.model.MallBanner>>
     * @Date 2018/11/9 14:17
     * @Param [HOME_BANNER]
     * @Description // 目前是数据库中所有的
     */
    @GetMapping("home_banner")
    @ApiOperation(value = "首页轮播图")
    public ServerResponse<List<MallBanner>> listHomeBanner(HttpServletRequest request, @RequestParam(value = "HOME_BANNER", defaultValue = "首页") String homeBanner) {

        return iMobileHomeService.listMeBanner(request, homeBanner);

    }

    /**
     * @return com.hmall.common.ServerResponse<java.util.List   <   com.hmall.model.MallBanner>>
     * @Date 2018/11/9 14:17
     * @Param []
     * @Description // 目前是数据库中所有的
     */
    @GetMapping("me_banner")
    @ApiOperation(value = "资讯轮播图")
    public ServerResponse<List<MallBanner>> listMeBanner() {

        return iMobileHomeService.listHomeBanner();
    }

    /**
     * @return com.hmall.common.ServerResponse<java.util.List   <   com.hmall.model.MallBanner>>
     * @Date 2018/11/9 14:17
     * @Param [ME_BANNER]
     * @Description // 目前是数据库中所有的
     */
    @GetMapping("report_banner")
    @ApiOperation(value = "锦纶快报轮播图")
    public ServerResponse<List<MallBanner>> listReportBanner(HttpServletRequest request, @RequestParam(value = "REPORT_BANNER", defaultValue = "锦纶快报") String meBanner) {

        return iMobileHomeService.listMeBanner(request, meBanner);
    }

    /**
     * @return com.hmall.common.ServerResponse<java.util.List   <   com.hmall.model.MallBanner>>
     * @Date 2018/11/9 14:17
     * @Param [ME_BANNER]
     * @Description // 目前是数据库中所有的
     */
    @GetMapping("quotation_banner")
    @ApiOperation(value = "行情快报轮播图")
    public ServerResponse<List<MallBanner>> listQuotationBanner(HttpServletRequest request, @RequestParam(value = "QUOTATION_BANNER", defaultValue = "行情快报") String meBanner) {

        return iMobileHomeService.listMeBanner(request, meBanner);
    }

    /**
     * @return com.hmall.common.ServerResponse<java.util.List   <   com.hmall.model.MallBanner>>
     * @Date 2018/11/9 14:18
     * @Param [mebanner]
     * @Description // 目前是数据库中所有的
     */
    @GetMapping("recommend_banner")
    @ApiOperation(value = "精选推荐轮播图")
    public ServerResponse<List<MallBanner>> listRecommendBanner(HttpServletRequest request, @RequestParam(value = "RECOMMEND_BANNER", defaultValue = "精选推荐") String meBanner) {

        return iMobileHomeService.listMeBanner(request, meBanner);
    }

    /**
     * @return com.hmall.common.ServerResponse<java.util.List   <   com.hmall.model.MallBanner>>
     * @Date 2018/11/9 14:18
     * @Param [ME_BANNER]
     * @Description // 目前是数据库中所有的
     */
    @GetMapping("bulletin_banner")
    @ApiOperation(value = "商城公告轮播图")
    public ServerResponse<List<MallBanner>> listBulletinBanner(HttpServletRequest request, @RequestParam(value = "BULLETIN_BANNER", defaultValue = "商城公告") String meBanner) {

        return iMobileHomeService.listMeBanner(request, meBanner);
    }

    /**
     * @return com.hmall.common.ServerResponse<java.util.List   <   com.hmall.model.MallBanner>>
     * @Date 2018/11/9 14:18
     * @Param [ME_BANNER]
     * @Description // 目前是数据库中所有的
     */
    @GetMapping("view_banner")
    @ApiOperation(value = "行业视点轮播图")
    public ServerResponse<List<MallBanner>> listViewBanner(HttpServletRequest request, @RequestParam(value = "VIEW_BANNER", defaultValue = "行业视点") String meBanner) {

        return iMobileHomeService.listMeBanner(request, meBanner);
    }


    /**
     * @return com.hmall.common.ServerResponse<java.util.List   <   com.hmall.vo.UserLikeVo>>
     * @Date 2018/11/9 14:18
     * @Param [token, count]
     * @Description // 用户专用猜你喜欢
     */
    @PostMapping("userLike")
    @ApiOperation(value = "用户猜你喜欢")
    public ServerResponse<List<UserLikeVo>> listUserLike(String token, @RequestParam(value = "count", defaultValue = "30") int count) throws Exception {

        SysUser user = tokenUtil.tokenToUser(jedisPool, token).getData();
        return iMobileHomeService.listUserLike(user.getUserId(), count);
    }


}
